﻿using System;
using CoreEx.Database.Metadata;
using LinFu.IoC.Interfaces;
using LinFu.Reflection;

namespace CoreEx.Database.Mapping
{
    /// <summary>
    /// Provides a base class for implementing the <see cref="ITableInfoMapper"/> interface.
    /// </summary>
    public abstract class TableInfoMapperBase : ITableInfoMapper, IInitialize<IServiceRequestResult>
    {     
        /// <summary>
        /// Initializes a new instance of the <see cref="TableInfoMapperBase"/> class.
        /// </summary>
        /// <param name="connectionName">The name of the connection used to retrieve a <see cref="IMetadataRepository"/> instance.</param>
        protected TableInfoMapperBase(string connectionName)
        {
            ConnectionName = connectionName;
        }

        /// <summary>
        /// Maps the <paramref name="type"/> to a corresponding <see cref="TableInfo"/> instance.
        /// </summary>
        /// <param name="type">The <see cref="Type"/> to map.</param>
        /// <returns><see cref="TableInfo"/></returns>
        public abstract TableInfo MapFrom(Type type);

        /// <summary>
        /// Gets the name of the connection used to retrieve a <see cref="IMetadataRepository"/> instance.
        /// </summary>
        protected string ConnectionName { get; private set; }

        /// <summary>
        /// Gets the <see cref="IMetadataRepository"/> that corresponds to the <see cref="ConnectionName"/>
        /// </summary>
        protected IMetadataRepository MetadataRepository { get; private set; }

        /// <summary>
        /// Gets the <see cref="IServiceContainer"/> that created this instance.
        /// </summary>
        protected IServiceContainer ServiceContainer { get; private set; }
    
        ///// <summary>
        ///// Initializes this <see cref="ITableInfoMapper"/> instance.
        ///// </summary>
        ///// <param name="source">The <see cref="IServiceContainer"/> that created this instance.</param>
        //public virtual void Initialize(IServiceContainer source)
        //{
        //    MetadataRepository = source.GetService<IMetadataRepository>(ConnectionName);
        //    ServiceContainer = source;
        //}
        public void Initialize(IServiceRequestResult source)
        {
            throw new NotImplementedException();
        }
    }
}
